package com.java.collection;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class QueueTests {
    static void blockQueue() throws InterruptedException {
        ArrayBlockingQueue<Integer> queue=new ArrayBlockingQueue<>(3);
       //LinkedBlockingQueue<Integer> queue1=new LinkedBlockingQueue<>(3);
        queue.put(10);
        queue.put(20);
        queue.put(30);
        System.out.println(queue);//[10,20,30]
        //queue.put(40);//阻塞式方法,容器满了会阻塞,假如是add方法,容器满了会抛出异常
        queue.take();
        queue.take();
        queue.take();
        System.out.println(queue);//[]
        queue.take();//阻塞式方法,容器空了会阻塞.
        System.out.println(queue);
    }
    public static void main(String[] args) throws InterruptedException {
        blockQueue();
    }
}
